package com.ai.util;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class OtherUtil {


    /**
     * 拆分文件
     *
     * @param dirName 需要拆分文件的目录
     * @param fileName 需要拆分的文件名
     * @param tmpDivideDir 目标拆分目录
     * @return 拆分后的文件名集合
     */
    public static List<String> divideFile(String dirName, String fileName, String tmpDivideDir) {
        long start = System.currentTimeMillis();
        List<String> fileList = new ArrayList<>();
        List<String> strings = ReadOrWriteFileUtil.readTxtLines(dirName, fileName);
        int fileCount = 0;
        for (String string : strings) {
            ReadOrWriteFileUtil.syncWriteTxt(tmpDivideDir, fileName + fileCount, string);
            if (ReadOrWriteFileUtil.getFileSize(tmpDivideDir, fileName + fileCount) >= 16) {
                fileList.add(fileName + fileCount);
                fileCount++;
            }
        }
        fileList.add(fileName + fileCount);
        System.out.println("=======================================================================");
        System.out.println("===============拆分文件完成=======拆分文件数量为：" + fileCount + "========================");
        System.out.println("=======================================================================");
        System.out.println("拆分文件耗时：" + (System.currentTimeMillis() - start));
        return fileList;
    }
}
